#ifndef _BARTER_SERVER_NETWORKSYSTEM_H_
#define _BARTER_SERVER_NETWORKSYSTEM_H_

#include "IBackEndModule.h"
#include "Mutex.h"
#include "Connection.h"
#include "NetworkMessage.h"

class NetworkSystem
{
private:
	int RunStatus; // Not running, Running, Stopping
	Mutex EventMutex;
	std::map<unsigned long, std::list<IBackEndModule*> > Events;
	NetworkSystem();
	NetworkSystem(const NetworkSystem&);
	NetworkSystem& operator=(const NetworkSystem&);
	std::string Host, Port;
	std::list<Connection*> Connections;
public:
	~NetworkSystem();
	static NetworkSystem& Instance();
	void Init();
	void Run();
	void Stop();
	void Close(Connection*);
	void CloseAllConnections();
	void DecodeMessage(Connection*, NetworkMessage*);
	void HookEvent(unsigned long, IBackEndModule*);
	void UnHookEvent(unsigned long, IBackEndModule*);
};

#define netSys NetworkSystem::Instance()

#endif // _BARTER_SERVER_NETWORKSYSTEM_H_
